<template>
	<view>
	
		
		<u-toast ref="uToast" />
		
		<u-popup mode="bottom" v-model="show" border-radius="14" @close="close">
		
				<view class="top u-flex u-row-between">
					<view class="u-flex" style="align-items: center;">
						<u-image src="/static/icon_address.png" width="60" height="60"></u-image>
						<view class="u-margin-left-20" style="width: 500rpx;" v-if="address.id">
							<view>
								<text style="font-size: 32rx;font-weight: bold;">{{address.realname}}</text>
								<text style="color:#999999;margin-left: 20rpx;">{{address.phone}}</text>
							</view>
							<view class="">
								{{address.address}}
							</view>
						</view>
						<view v-else style="font-size: 32rpx;font-weight: bold;margin-left: 20rpx;" hover-class="none" @click="selectaddress">
						  请先选择收货地址
						</view>
					</view>
					<u-icon name="edit-pen" color="#628DFF" size="40" @click="changeAddress" v-if="address.id"></u-icon>
				</view>
				
				
				<view class="u-flex " style="padding: 40rpx 40rpx 0 40rpx;">
				   <u-image :src="info.cover" width="150" height="150"></u-image>	
				   <view class="u-padding-left-20">
					   <view>{{info.goodsName}}</view>
					   <view style="font-size: 56rpx;color:#FF6450;">￥{{info.price}}</view>
				   </view>
				</view>
				
				<u-button shape="circle" :custom-style="{background:'#FF6450',color:'#fff',margin:'40rpx auto',width:'600rpx'}"
					@click="submit">
					已经选择该商品，点击免单</u-button>
		
		</u-popup>
	</view>
</template>

<script>
	export default{
		watch:{
			show:{
                immediate: true,
				handler(v){
					
					// 获取地址信息
					if(v){
						this.getAddress()
					}
					
				}
			}
		},
		data(){
			return{
				show:false,
				list:[],
				address:"",
				info:""
			}
		},
		methods:{
			selectaddress(){
				this.show=false;
				uni.navigateTo({
					url:"/pages/address/addAddress"
				})
			},
	
			close(){
				this.$parent.surepop=false
			},
			getAddress() {
				this.$u.post('/api/user/address', {
					
				}, {}).then(res => {
				    if(res.data.length){
						this.address=res.data[0]
					}
				}).catch(err => {})
			
			},
			changeAddress(){
				uni.navigateTo({
					url:"/pages/address/index"
				})
				this.$parent.surepop=false
			},
			submit(){
	            if(!this.address.id){
					this.$refs.uToast.show({
						title: '请先选择地址',
						type: 'error',
										
					})
					return
				}
				
				this.$u.post('/api/indent/bargain', {
					address_id:this.address.id,
					goods_id:this.$parent.id,
					goods_spec_id:this.info.spec.length?this.$parent.Sid:""
				}, {}).then(res => {
					  this.$refs.uToast.show({
						title: '砍价成功',
						type: 'success',
						callback :()=>{
							uni.redirectTo({
								url:"/pages/kanjia/likeProduct?id="+res.data.orderId
							})
							this.$parent.surepop=false
						}
					  })
					
					
				}).catch(err => {})
			
			}
		}
	}
</script>

<style>
	
	.mode {
	
		background: #FFFFFF;
		box-shadow: 0px 4rpx 6rpx rgba(209, 209, 209, 0.26);
		border-radius: 20rpx;
		width: 690rpx;
		margin: 40rpx auto;
	}
	
	.top {
		width: 690rpx;
		background: #FFFFFF;
		box-shadow: 0px 4rpx 6rpx rgba(209, 209, 209, 0.26);
		border-radius: 20rpx;
		margin: 40rpx auto;
		padding: 30rpx;
		display: flex;
		justify-content: space-between;
	}
</style>
